Repository navigation
feat(util.dataset): add simulate_if_needed one-line auto-simulate helper - #670
Merged
Merged
Conversation
Adds aa.util.dataset.simulate_if_needed(dataset_path, simulator), which runs the simulator script in a subprocess (sys.executable, check=True) only when should_simulate(dataset_path) is True. Subprocess isolation is kept deliberately (not runpy) so simulator JAX/matplotlib state cannot leak into the caller. Accepts str or Path for both args and returns whether the simulator ran. The should_simulate docstring's usage example now points at the helper. Tests mock subprocess.run for both branches and both arg types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016nhQ8NyQo2s3YUk8eUrrB3
This was referenced Nov 1, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of #669.
Summary
aa.util.dataset.simulate_if_needed(dataset_path, simulator)toautoarray/util/dataset_util.py. Whenshould_simulate(str(dataset_path))is True it runssubprocess.run([sys.executable, str(simulator)], check=True). It returns whether the simulator ran.runpy, so the simulator's JAX/matplotlib/module state cannot leak into the calling script.check=Truemeans a failing simulator raises instead of letting the caller load a missing dataset.strorPathfor both arguments.should_simulatedocstring now points at the helper.This lets workspaces replace the 8-line block:
with:
The workspace sweep (phase 3) waits for a release. The companion PyAutoHands PR makes
check_dataset_allowlistrecognise the new call, so swept scripts stay guarded.Testing
test_autoarray/util/test_dataset_util.pymocksubprocess.run. They check that it is called exactly once with[sys.executable, str(simulator)]andcheck=Truewhenshould_simulateis True, that it is not called when False, that both str and Path arguments work, and that a missing dataset triggers the run.pytest test_autoarray/util: 148 passed.al.util.dataset/ag.util.datasetshould expose the helper automatically, because they re-export this module (the workspaces already callal.util.dataset.should_simulate). That wasn't checked against PyAutoGalaxy/PyAutoLens in this session.Merge mode: human
/prm.Generated by Claude Code